import {type BaseResponse} from '@/webApis/base';
import { UUID } from "@/utils/util";

export interface CommodityDetailModel {
    id: string,
    banners: string[],
    realPrice: number,
    marketPrice: number,
    soldNum: number,
    tags: string[],
    title: string,
    desc: string[],
    soldout: boolean,
}


export namespace commodity{
	/**
	 * 获取商品分页
	 */
	export const getPageListAsync = async (data:{pageNum:number, pageSize:number,menuName:string}): Promise<BaseResponse> => {
		return new Promise((resolve) => {
		    setTimeout(() => {
		        let response:BaseResponse = {
		            rows: [],
					total: 35,
		        }
		        for (let i = 0; i < data.pageSize; i++) {
		            response.rows.push({
		                id: UUID(),
		                orderStatus: i % 4 + 1,
		                name: `${data.menuName}-${data.pageNum}-${i}`,
		                price: Number((Math.random() * 20000 + 100).toFixed(0)),//分
		                count: Number((Math.random() * 5 + 1).toFixed(0)),//正整数
		            });
		        }
		        resolve(response)
		    }, 200);
		})
	}
	
	/**
	 * 商品详情
	 */
	export const getDetailAsync = async (id: string): Promise<BaseResponse<CommodityDetailModel>> => {
	    return new Promise((resolve) => {
	        setTimeout(() => {
	            const detail: CommodityDetailModel = {
	                id: id,
	                banners: ['https://cdn-we-retail.ym.tencent.com/tsr/goods/nz-08a.png',
	                    'https://cdn-we-retail.ym.tencent.com/tsr/goods/nz-08a1.png',
	                    'https://cdn-we-retail.ym.tencent.com/tsr/goods/nz-08b.png',],
	                realPrice: 9900,
	                marketPrice: 19900,
	                soldNum: 102,
	                tags: ['满100减10', '满200减20', '满500减50'],
	                title: '纯色纯棉休闲圆领短袖T恤纯白亲肤厚柔软细腻面料纯白短袖套头T恤',
	                desc: [
	                    'https://cdn-we-retail.ym.tencent.com/tsr/goods/nz-08c.png',
	                    'https://cdn-we-retail.ym.tencent.com/tsr/goods/nz-08d.png',
	                ],
	                soldout: false,
	            }
	            resolve({
					rows:detail,
				});
	        }, 100);
	    })
	}
}